﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 图形控件
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            Loaded += (s, e) =>
            {
                int number = 10;
                Task.Run(() =>
                {
                    while (true)
                    {
                        if (number == 1)
                            number = 10;
                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            flowLine.StrokeDashOffset = number;
                        }));
                        number--;
                        Thread.Sleep(250);
                    }
                });
            };
        }



        private int count = 0;
        private Polyline polyline = null;

        private void Window_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (count++ == 0)
            {
                polyline = new Polyline();
                polyline.StrokeThickness = 5;
                polyline.Stroke = Brushes.Red;
                canvas.Children.Add(polyline);
            }

            var point = e.GetPosition(canvas);
            polyline.Points.Add(point);
        }

        private void Window_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            count = 0;
        }
    }
}